package com.huike.clues.service.impl;


import com.huike.clues.domain.TbClue;
import com.huike.clues.domain.TbClueTrackRecord;
import com.huike.clues.domain.vo.ClueTrackRecordVo;
import com.huike.clues.mapper.TbClueMapper;
import com.huike.clues.mapper.TbClueTrackRecordMapper;
import com.huike.clues.service.ITbClueTrackRecordService;
import com.huike.common.utils.DateUtils;
import com.huike.common.utils.SecurityUtils;
import com.huike.common.utils.bean.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 线索跟进记录Service业务层处理
 *
 * @date 2022-04-22
 */
@Service
public class TbClueTrackRecordServiceImpl implements ITbClueTrackRecordService {

    @Autowired
    public TbClueTrackRecordMapper tbClueTrackRecordMapper;

    @Autowired
    public TbClueMapper tbClueMapper;

    /**
     * @param clueId
     * @return List<TbClueTrackRecord>
     * @description: 查询线索跟进记录列表
     */
    @Override
    public List<TbClueTrackRecord> selectByClueId(Long clueId) {
        return tbClueTrackRecordMapper.selectByClueId(clueId);
    }

    /**
     * @param tbClueTrackRecord
     * @return void
     * @description: 新增线索跟进记录
     */
    @Override
    public void add(ClueTrackRecordVo tbClueTrackRecord) {
        TbClue clue = new TbClue();
        BeanUtils.copyBeanProp(clue, tbClueTrackRecord);
        //加id
        clue.setId(tbClueTrackRecord.getClueId());
        //加创建人id
        clue.setUpdateBy(SecurityUtils.getUsername());
        //加时间
        Date nowDate = DateUtils.getNowDate();
        clue.setUpdateTime(nowDate);
        //加下次更新时间
        clue.setNextTime(null);
        //修改线索管理
        tbClueMapper.updateTbClue(clue);

        TbClueTrackRecord trackRecord = new TbClueTrackRecord();

        BeanUtils.copyBeanProp(trackRecord, tbClueTrackRecord);

        //加创建人id
        trackRecord.setCreateBy(SecurityUtils.getUsername());
        //加时间
        trackRecord.setCreateTime(nowDate);
        //新增线索跟进记录
        tbClueTrackRecordMapper.insert(trackRecord);
    }
}
